<?php

namespace app\financial\model;

use think\Db;
use \think\Model;
class AwardCardModel extends Model
{
    public function getList($filter)
    {
        $where=['c.delete_time'=>0,'aw.delete_time'=>0];
        if(!empty($filter['is_used']))
        {
            $where['c.is_used']=1;
        }
        if(isset($filter['is_used'])  && $filter['is_used']==0)
        {
            $where['c.is_used']=0;
        }
        if(!empty($filter['card_number']))
        {
            $where['aw.card_number']=$filter['card_number'];
        }
        if(!empty($filter['tname']))
        {
            $where['t.name']=['like',"%".trim($filter['tname'])."%"];
        }
        if(!empty($filter['code']))
        {
            $where['t.code|t.old_code']=['like',"%".trim($filter['code'])."%"];
        }
        $field='c.*,aw.*,u.realname realname,ao.id aoid,ao.create_time aocreate_time,t.name tname,t.code tcode,uu.user_login uuuser_login';
        $data=Db::table('cmf_award_student')->alias('c')->field($field)
            ->join('award_card aw','aw.id=c.award_id')
            ->join('user u','u.id=c.u_id',$type='left')
            ->join('user uu','uu.id=aw.create_card_user_id',$type='left')
            ->join('student t','t.id=c.student_id',$type='left')
            ->join('award_order ao','ao.award_student_id=c.award_id',$type='left')
            ->where($where)
            ->order('c.id','DESC')
            ->paginate(10,false,['query' => $filter]);

        return $data;

    }
}